
<?php 
	//print_r($current_page);
	$start_number = (($current_page -1 ) * $default_per_page) ;
	if($start_number <= 0)
		$start_number = 0;
	$column_width = (int)(80/count($columns));
	
	if(!empty($list)){
?><div class="bDiv" >
		<table cellspacing="0" cellpadding="0" border="0" id="flex1" width="100%">
		<thead>

			<tr class='header hDiv ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons'>
				<?php if(!$unset_numbering){?>
				<th align="center" valign="middle" abbr="number" axis="col1" class="numbering" >
					<div class="">
						<?php echo $this->l('list_numbering'); ?>
					</div>
				</th>
				<?php }?>
				<?php foreach($columns as $column){?>
				<th valign="middle" class="<?php echo $column->field_name?>">
					<div class="text-left field-sorting <?php if(isset($order_by[0]) &&  $column->field_name == $order_by[0]){?><?php echo $order_by[1]?><?php }?>" 
						rel='<?php echo $column->field_name?>'>
						<?php echo $column->display_as?>
					</div>
				</th>
				<?php }?>

				<?php if(!$unset_delete || !$unset_edit || !$unset_read || !empty($actions)){?>
				<th align="left" abbr="tools" axis="col1" class="tools"   valign="middle" >
					<div class="">
						<?php echo $this->l('list_actions'); ?>
					</div>
				</th>
				<?php }?>
				
			</tr>
		</thead>		
		<tbody>
		<?php foreach($list as $num_row => $row){ $start_number++?>        
		<tr class="tr-grouping tr-<?php echo strtolower(preg_replace('/\s/i', '-', $subject))?>" tid="<?php echo $row->id ?>"  <?php if($num_row % 2 == 1){?>class="erow"<?php }?>>
			
			<?php if(!$unset_numbering){?>
			<td align="center" >
				<div style="text-align:center">
					<?php echo $start_number; ?>
				</div>
			</td>
			<?php }?>
			
			<td colspan="4" class="field_nip"><div class="text-left"> <?php echo $row->nip?></div></td>
			
			<?php if(true){?>
			<?php $ci =& get_instance();?>
			<td align="left">
				<div class="tools">
					<a <?php echo !($row->jml > 0)?' style="visibility:hidden" ':'style="float:left"';?> onclick="query_form(this)" href='<?php echo site_url('master/aktifitas_pegawai/cetak_pdf/'.$row->id);?>' title='<?php echo 'Cetak Laporan'?>' class="read_button cetak_pdf"><span class='edit-icon ui-corner-all ui-icon ui-icon-print'></span></a>
					<?php if($ci->LoginInfo->is('Lurah')):?>
					<a <?php echo !(1> 0)?' style="visibility:hidden" ':'style="float:left"';?> onclick="$('#add-button').click();gcConf.current_nip='<?php echo $row->id?>';" href='javascript:;' title='<?php echo 'Tambah Aktifitas ';?>' class="read_button add_aktifitas"><span class='edit-icon ui-corner-all ui-icon ui-icon-plus'></span></a>
					<a <?php echo !($row->jml > 0)?' style="visibility:hidden" ':'style="float:left"';?> onclick="query_form(this)" href='<?php echo site_url('master/aktifitas_pegawai/hapus_semua/'.$row->id);?>' title='<?php echo 'Hapus Semua Aktifitas ';?>' class="read_button hapus_semua_aktifitas"><span style="line-height: 17px;" class='edit-icon  fa fa-eraser'></span></a>
					<?php endif;?>
					<div class="clear"></div>
				</div>
			</td>
			<?php }?>
		</tr>
<?php } ?>        
		</tbody>
		</table>
	</div>
<?php }else{?>
	<br/>
	&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $this->l('list_no_items'); ?>
	<br/>
	<br/>
<?php }?>	
<script type="text/javascript">
function query_form(el){
    var grid_cls ='.grd-<?php echo strtolower(str_replace(' ', '-', $subject))?>';
    var grid_obj ='grd_<?php echo strtolower(str_replace(' ', '_', $subject))?>';
	if(typeof window[grid_obj] != 'undefined')
	if(typeof window[grid_obj]['QueryForm'] != 'undefined'){
		window[grid_obj]['QueryForm'].Reset = true;
		window[grid_obj]['QueryForm']();
	}
	////console.log(window[grid_obj])
}
function expandGrid(el,nip)
{
	var is_open = !$(el).data('is_open');
	


	var tr = $(el).closest('tr');
	var id_aktifitas = tr.attr('tid');
	console.log($('tr.pid-'+id_aktifitas));
	console.log('tr.pid-'+id_aktifitas);

	var collapser_icon = $(el).find('i.collapser-icon');
	
	gcConf.active_grouping[id_aktifitas] = is_open;

	if(is_open)
	{
		collapser_icon.removeClass('fa-plus-square-o');
		collapser_icon.addClass('fa-spinner fa-spin');

		

		setTimeout(function(){
			$.post('<?php echo base_url()?>master/aktifitas_pegawai/data/'+nip+'/',{nip:nip,is_ajax:true},function(result){
				tr.after(result);
				
				collapser_icon.removeClass('fa-spinner fa-spin');
				collapser_icon.addClass('fa-minus-square-o');
				
				$(el).data('is_open',true);
			});

		},200);
	}
	else
	{
		$('tr.pid-'+id_aktifitas).fadeOut("normal", function() { $(this).remove(); } );
		
		collapser_icon.removeClass('fa-minus-square-o');
		collapser_icon.addClass('fa-plus-square-o');

		$(el).data('is_open',false);
	}

	//.remove();
	
	
	

	
}
$(document).ready(function(){

	// $(grid_cls+' .add_button,'+grid_cls+' .edit_button').each(function(){
	// 	$(this).click(function(){
			
	// 	});
	// })
	$('td.field_nip').each(function(i,td){
		var div = $(this).find('>div');
		var tr  = $(this).closest('tr');
		var id_aktifitas = tr.attr('tid');
		if(!$(this).data('hasCollapser'))
		{
	
			var collapser = $('<a  onclick="expandGrid(this,\''+id_aktifitas+'\')" style="float:left;margin:5px" class="collapser_'+id_aktifitas+'" href="javascript:;"><i class="collapser-icon fa fa-plus-square-o"></i></a>');
			$(this).prepend(collapser);	
			$(this).data('hasCollapser',true);
		}
		
		console.log(div)
	});

	if(typeof gcConf.active_grouping == 'undefined')
		gcConf.active_grouping = {};
	else
	{
		$.each(gcConf.active_grouping,function(k,v){
			if(v){
				$('a.collapser_'+k).trigger('click');
			}
		});
	}

	$('a.read_button.hapus_semua_aktifitas').unbind('click').click(function (argument) {
		var self = this;
		confirm_alert('Peringatan','<i class="fa fa-exclamation-triangle" style="width: 12px; float: left; font-size: 65px; margin-right: 43px; color: #333;"></i>&nbsp;Apakah anda yakin ingin mengosongkan data Aktifitas pegawai ini ?',function(){
			$.post(self.href,function(r){
				refresh_grid();
			})	
		},function(){})
	

		return false;
	});
	$('a.read_button.cetak_pdf').unbind('click').click(function(){
		window.open(this.href);
		return false;
	});
})
</script>